﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Kevin.Framework.Data.OrmMapping;

namespace Kevin.Framework.Data
{
    public static class DataTableExtend
    {
        /// <summary>
        /// 将DataTable转换为实体集
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <returns></returns>
        public static List<T> ToEntity<T>(this DataTable table) where T : EntityBase,new()
        {
            List<T> result = new List<T>();

            foreach (DataRow dr in table.Rows)
            {
                T obj=new T();
                ORMapping.DataRowToObject(dr, obj);
                result.Add(obj);
            }

            return result;
        }
    }
}
